import jsCookie from 'js-cookie'

interface cookieApi {
  expires?: number | Date
  path?: string
  domain?: string
}
function set(key: string, value: any, options: cookieApi = { expires: 7 }): void {
  let expires = options.expires
  options.expires = expires ? expires : 7
  jsCookie.set(key, JSON.stringify(value), options)
}

function get(key: string): any {
  let value = jsCookie.get(key)
  return value != undefined && value != 'undefined' ? JSON.parse(value) : value
}

function remove(key: string, options?: cookieApi): void {
  jsCookie.remove(key, options)
}

export const cookie = {
  set,
  get,
  remove
}
